package net.kangyee.eventmanager.commands;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.kangyee.eventmanager.EventManager;
import net.kangyee.eventmanager.util.MessageManager;

public class CmdCmd extends EventManagerCommand {

	private EventManager plugin;
	
	public CmdCmd(EventManager plugin){
		this.plugin = plugin;
	}
	
	public void onCommand(Player player, String[] args){
        if(args.length == 3){
        	if(!plugin.playerStateChecker(player, args[2])){
        		return;
        	}
        	String localCmd = args[1].replaceAll("%player%", args[2]).replaceAll("_", " ");
        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), localCmd);
        	MessageManager.sendNormalMessage(player, "&f成功执行指令:&6" + localCmd);
        }else{
        	for(Player localPlayer : plugin.regPlayers.keySet()){
            	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), args[1].replaceAll("%player%", localPlayer.getName()).replaceAll("_", " "));
        	}
        	MessageManager.sendNormalMessage(player, "&f成功执行指令(全体):&6" + args[1].replaceAll("_", " "));
        }
	}

	public String getCmdName(){
		return "cmd";
	}

	public String getArgs(){
		return "<指令> [游戏名]";
	}
	
	public int getMaxArgs(){
		return 3;
	}

	public int getMinArgs(){
		return 2;
	}

	public String getPermission(){
		return "eventmanager.admin." + getCmdName();
	}

	public boolean getStateRequire(){
		return true;
	}

	public boolean getRegPCRequire() {
		return true;
	}
}
